home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2008 March / MAC_easy_03_08.iso / Software / Shareware / Isolator-3.3.dmg / Docs / Source Code / BlackView.m < prev    next >
Encoding:
Text File  |  2008-06-04  |  1.1 KB  |  58 lines

  1. //
  2. //  BlackView.m
  3. //  Isolator
  4. //
  5. //  Created by Ben Willmore on 08/02/2007.
  6. //  Copyright 2007 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #include "Cocoa/Cocoa.h"
  10. #import "BlackView.h"
  11.  
  12. @implementation BlackView
  13.  
  14. -(id) initWithFrame:(NSRect)frameRect
  15. {    
  16.     [super initWithFrame:(NSRect)frameRect];
  17.  
  18.     NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  19.     if (![defaults objectForKey:@"BackgroundColor"]) {
  20.         NSData *theData=[NSArchiver archivedDataWithRootObject:[NSColor blackColor]];
  21.         [[NSUserDefaults standardUserDefaults] setObject:theData forKey:@"BackgroundColor"];
  22.     }
  23.  
  24.     [self setColor];
  25.     
  26.     return self;
  27. }
  28.  
  29. -(void) drawRect:(NSRect)theRect
  30. {
  31.     [bgColor set];
  32.     NSRectFill(theRect);
  33. }
  34.  
  35. -(void) setColor
  36. {
  37.     if (bgColor)
  38.         [bgColor release];
  39.  
  40.     NSData *theData=[[NSUserDefaults standardUserDefaults] dataForKey:@"BackgroundColor"];
  41.     if (theData)
  42.         bgColor = (NSColor *)[NSUnarchiver unarchiveObjectWithData:theData];
  43.     else
  44.         bgColor = [NSColor blackColor];
  45.  
  46.     [bgColor retain];
  47.  
  48.     [self setNeedsDisplay:YES];
  49. }
  50.  
  51. -(void) dealloc
  52. {
  53.     [bgColor release];
  54.     [super dealloc];
  55. }
  56.  
  57. @end
  58.